<template>
	<view class="examination">
		<view class="examination_name">{{courseExamInfo.examName}}</view>
		<view class="examination_info" @tap="goExamIntroduce(courseExamInfo.id)">
			<view class="examination_info_top">
				<view class="">考试信息</view>
				<uni-icons type="right" :color="'#1A1A1A'" :size="16"></uni-icons>
			</view>
			<view class="examination_info_bottom">
				<view class="examination_info_bottom_item">
					<view class="">{{courseExamInfo.examTime || '不限'}}</view>
					<text>考试时长(分钟)</text>
				</view>
				<view class="examination_info_bottom_item">
					<view class="">{{courseExamInfo.totalQuestion}}</view>
					<text>题目数量</text>
				</view>
				<view class="examination_info_bottom_item">
					<view class="">{{courseExamInfo.totalScore}}</view>
					<text>试题总分</text>
				</view>
			</view>
		</view>
		<view class="examination_record" v-if="courseExamRecordList.length > 0">
			<view class="examination_record_title">考试记录</view>
			<view class="examination_record_item" v-for="(item,index) in courseExamRecordList" :key="index"
				@tap="goExamDetails(item.id)">
				<view class="examination_record_item_top">
					<view class="">交卷时间：{{item.submitTime}}</view>
					<text class="">· {{examStatusText(item.status)}}</text>
				</view>
				<view class="examination_record_item_bottom">[分数：{{item.score}}]</view>
			</view>
		</view>
		<!--  -->
		<view class="bottom_btn">
			<view class="xjs-btn-primary" v-if="
			courseExamInfo.status == 1 && courseExamInfo.remainingNum > 0 && 
			(courseExamRecordList.length == 0 || ![0,5].includes(Number(courseExamRecordList[0].status)))"
				@tap="goExam(courseExamInfo.id)">前去考试</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { useUserStoreToRefs } from '@/store/useUserStore'
	const { userInfo } = useUserStoreToRefs()
	import api from '@/api'
	const props = defineProps({
		courseExamInfo: {
			type: Object,
			default: {}
		},
		courseExamRecordList: {
			type: Object,
			default: []
		},
		couresId: {
			type: [Number, String],
			default: ''
		},
		getCourseDetails: {
			type: Function
		}
	})
	const examStatusText = (val) => {
		let text = ''
		switch (Number(val)) {
			case 0:
				text = '考试待批阅'
				break;
			case 1:
				text = '批阅已通过'
				break;
			case 2:
				text = '批阅未通过'
				break;
			case 3:
				text = '考试未通过'
				break;
			case 4:
				text = '考试中'
				break;
			case 5:
				text = '考试通过'
				break;

		}
		return text
	}
	const goExamDetails = (id) => {
		uni.navigateTo({
			url: `/pages/businessSchool/examDetails/index?id=${id}`
		})
	}
	const goExamIntroduce = (examId) => {
		uni.navigateTo({
			url: `/pages/businessSchool/examIntroduce/examIntroduce?examId=${examId}`
		})
	}
	const goExam = async (examId) => {

		if (!userInfo.value) {
			uni.navigateTo({
				url: '/pages/login/index'
			})
			return
		}
		const resCheck : any = await api({
			method: 'get',
			url: `/mall/exam/info/${props.courseExamInfo.id}`
		})
		const resCheckTwo : any = await api({
			method: 'get',
			url: `/mall/course/course/${props.couresId}`
		})

		if (resCheck.data.status == 2) {
			uni.showToast({
				title: '考试已下架',
				icon: 'none'
			})
			await props.getCourseDetails(props.couresId)
			return
		}
		if (resCheckTwo.data.status == 2) {
			uni.showToast({
				title: '课程已下架/删除',
				icon: 'none'
			})
			await props.getCourseDetails(props.couresId)
			return
		}
		uni.navigateTo({
			url: `/pages/businessSchool/partExam/partExam?examId=${examId}`
		})
	}
</script>

<style lang="scss" scoped>
	.examination {
		margin: 0 auto;
		padding-top: 48rpx;
		width: 686rpx;
	}

	.examination_name {
		margin-bottom: 40rpx;
		font-size: 32rpx;
		color: #1A1A1A;
		font-weight: bold;
		line-height: 1.4;
	}

	.examination_info {

		background-color: #fff;
		padding: 40rpx 32rpx;
		border-radius: 24rpx;
		line-height: 1;

		.examination_info_top {
			margin-bottom: 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			view {
				font-size: 32rpx;
				color: #1B2120;
				font-weight: bold;
			}
		}

		.examination_info_bottom {
			display: flex;
			justify-content: space-between;

			.examination_info_bottom_item {
				padding: 48rpx 0;
				width: 200rpx;
				box-sizing: border-box;
				background-color: #FCF2F4;
				border-radius: 24rpx;
				display: flex;
				flex-direction: column;
				align-items: center;


				view {
					margin-bottom: 24rpx;
					font-size: 30rpx;
					color: #1B2120;
					font-weight: bold;
				}

				text {
					font-size: 26rpx;
					color: #5C5E5E;
				}
			}
		}
	}

	.examination_record {
		margin-top: 24rpx;
		padding: 32rpx;
		padding-top: 40rpx;
		background-color: #fff;
		border-radius: 24rpx;

		.examination_record_title {
			padding-bottom: 24rpx;
			font-size: 32rpx;
			color: #1B2120;
			font-weight: bold;
			line-height: 1;
		}

		.examination_record_item {
			margin-top: 16rpx;
			padding: 32rpx 24rpx;
			width: 622rpx;
			box-sizing: border-box;
			background-color: #F9F6F6;
			border-radius: 16rpx;
			line-height: 1;

			.examination_record_item_top {
				margin-bottom: 16rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				view {
					font-size: 28rpx;
					color: #5C5E5E;
				}

				text {
					font-size: 22rpx;
					color: #1B2120;
				}

				.via_color {
					color: #08B66E;
				}

				.not_via_color {
					color: #FF5253;
				}
			}

			.examination_record_item_bottom {
				font-size: 22rpx;
				color: #7C807F;
			}
		}
	}

	.bottom_btn {
		position: fixed;
		bottom: 0;
		left: 0;
		padding: 8rpx 40rpx;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 8rpx);
		padding-bottom: calc(env(safe-area-inset-bottom) + 8rpx);
		width: 100%;
		box-sizing: border-box;
		background-color: #fff;
		border-top: 1rpx solid #CCCCCC;
		/* view {
			width: 100%;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: linear-gradient( 90deg, #FF6188 0%, #FF5252 100%);
			border-radius: 62rpx;
			line-height: 1;
			font-size: 28rpx;
			color: #fff;
		}
		.bottom_btn_prohibit{
			
		} */
	}
</style>